﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebTemplate.DAL.Entities;

namespace WebTemplate.DAL.Repositories
{
   public class ScheduleRepository
    {
       public List<Schedule> Select(ScheduleSearchCriteria item)
       {
           SqlConnection connection = new SqlConnection();
           connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

           SqlCommand command = new SqlCommand();
           command.Connection = connection;
           command.CommandText = "[Schedule_Select]";
           command.CommandType = System.Data.CommandType.StoredProcedure;
           command.Parameters.AddWithValue("@CourseSemesterId", item.CourseSemesterId);
           command.Parameters.AddWithValue("@StudentId", item.StudentId);

           connection.Open();

           SqlDataReader reader = command.ExecuteReader();

           List<Schedule> lst = new List<Schedule>();
           while (reader.Read())
           {
               Schedule obj = new Schedule();

               obj.CourseName = reader.GetString(0);
               obj.CourseSemesterId = reader.GetInt32(1);
               obj.CourseId = reader.GetInt32(2);
               obj.DoctorId = reader.GetInt32(3);
               obj.StudentId = reader.GetInt32(4);
      

               lst.Add(obj);
           }
           connection.Close();

           return lst;
       }
    }
}
